﻿using Microsoft.Extensions.DependencyInjection;
using Modules.BankSpecialAccount.Entitys;
using Modules.BankSpecialAccount.Repositories;
using PmSoft;
using PmSoft.ApplicationContext;
using PmSoft.Exceptions;

namespace Modules.BankSpecialAccount
{
    [UseDI(ServiceLifetime.Scoped)]
    public class BankSpecialAccountPaymentService
    {
        private readonly BankSpecialAccountPaymentRepository repository;
        private readonly IApplicationContext applicationContext;
        private readonly BankSpecialAccountService projectSpecialAccountService;

        public BankSpecialAccountPaymentService(BankSpecialAccountPaymentRepository repository, IApplicationContext applicationContext, BankSpecialAccountService projectSpecialAccountService)
        {
            this.repository = repository;
            this.applicationContext = applicationContext;
            this.projectSpecialAccountService = projectSpecialAccountService;
        }

        public void CreateProjectSpecialAccountPayment(BankSpecialAccountPayment entity)
        {
            repository.Insert(entity);
        }

        public void DeletProjectSpecialAccountPayments(IEnumerable<int> ids)
        {
            foreach (int id in ids)
                DeleteProjectSpecialAccountPayment(id);
        }

        public void DeleteProjectSpecialAccountPayment(int id)
        {
            repository.DeleteByEntityId(id);
        }

        public BankSpecialAccountPayment? GetProjectSpecialAccountPayment(int id)
        {
            return repository.Get(id);
        }

        public IEnumerable<BankSpecialAccountPayment> GetProjectSpecialAccountPayments(IEnumerable<int> ids)
        {
            return repository.PopulateEntitiesByEntityIds(ids);
        }

        public void UpdateProjectSpecialAccountPayment(BankSpecialAccountPayment entity)
        {
            repository.Update(entity);
        }

        public IPagedList<BankSpecialAccountPayment> GetProjectSpecialAccountPayments(BankSpecialAccountPaymentQuery query, int pageIndex, int pageSize)
        {
            return repository.GetProjectSpecialAccountPayments(query, pageIndex, pageSize);
        }

        public IEnumerable<BankSpecialAccountPayment> GetProjectSpecialAccountPaymentsByProjectIds(IEnumerable<int> projectIds)
        {
            return repository.GetProjectSpecialAccountPaymentsByProjectIds(projectIds);
        }

        /// <summary>
        /// 是否存在收支信息
        /// </summary>
        /// <param name="serialNumber"></param>
        /// <param name="bankSerialNumber"></param>
        /// <param name="bankNo"></param>
        /// <returns></returns>
        public bool ExistPayment(string serialNumber, string bankSerialNumber, string bankNo)
        {
            return repository.ExistPayment(serialNumber, bankSerialNumber, bankNo);
        }
    }
}